package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.NewBanners;
import com.ytjj.qmyx.admin.model.dto.NewBannersDto;
import com.ytjj.qmyx.admin.service.NewBannerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * banners后台配置
 */
@RestController
@RequestMapping("/newBanners")
public class NewBannersController {

    @Resource
    private NewBannerService newBannerService;

    /**
     * 新增
     * @param newBanners
     * @return
     */
    @PostMapping("/insertBanners")
    public CommonResult insertBanners(@RequestBody NewBanners newBanners) {
        int b = newBannerService.insertBanners(newBanners);
        if (b > 0) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询
     * @param newBannersDto
     * @return
     */
    @PostMapping("/findBannersAll")
    public CommonResult findBannersAll(@RequestBody NewBannersDto newBannersDto) {
        return CommonResult.success(newBannerService.findBannersAll(newBannersDto));
    }

    /**
     * 修改
     * @param newBanners
     * @return
     */
    @PostMapping("/updateBanners")
    public CommonResult updateBanners(@RequestBody NewBanners newBanners) {
        int i = newBannerService.updateBanners(newBanners);
        if (i > 0) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }
}
